package com.lagou.server;

import com.lagou.pojo.RpcRequest;
import com.lagou.service.IUserService;

import java.util.UUID;

public class ClientBootstrap {
    public static final String providerName = "UserService#sayHello#";

    public static void main(String[] args) throws InterruptedException {
        rpc2();
    }

    private void rpc1() throws InterruptedException {
        RpcConsumer consumer = new RpcConsumer();
        IUserService service = (IUserService) consumer.createProxy(IUserService.class, providerName);
        for(;;){
            Thread.sleep(1000);
            System.out.println(service.sayHello("are u ok ?"));
        }
    }

    private static void rpc2() throws InterruptedException {
        RpcConsumer consumer = new RpcConsumer();

        IUserService service = (IUserService) consumer.createProxy2(IUserService.class);
        while(true){
            System.out.println("开始组装参数=======>>>");
            RpcRequest msg = new RpcRequest();
            msg.setRequestId(UUID.randomUUID().toString());
            msg.setClassName("Name");
            msg.setMethodName("bark");
            msg.setParameters(new Object[]{"tom",666});
            msg.setParameterTypes(new Class[]{int.class, Void.class, Enum.class});
            System.out.println("客户端入参：" + msg.toString());
            String result = service.invoke(msg);
            System.out.println("客户端接收到出参：" + result);
            Thread.sleep(3000);
        }

    }
}
